package com.cainiao.controller;

import com.cainiao.annotation.Log;
import com.cainiao.pojo.Dept;
import com.cainiao.pojo.Result;
import com.cainiao.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;
    @GetMapping("/depts")
    public Result list() {
        return Result.success(deptService.findDept());
    }

    @Log
    @DeleteMapping("/depts")
    public Result delete(Integer id) {
        deptService.delete(id);
        return Result.success();
    }

    @Log
    @PostMapping("/depts")
    public Result add(@RequestBody Dept dept) {
        deptService.add(dept);
        return Result.success();
    }

    @GetMapping("/depts/{id}")
    public Result findById(@PathVariable Integer id) {
        return Result.success(deptService.findById(id));
    }

    @Log
    @PutMapping("/depts")
    public Result update(@RequestBody Dept dept) {
        deptService.update(dept);
        return Result.success();
    }
}
